package com.github_Dididipapa.shortlink.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github_Dididipapa.shortlink.project.common.result.R;
import com.github_Dididipapa.shortlink.project.common.result.Rs;
import com.github_Dididipapa.shortlink.project.dto.req.*;
import com.github_Dididipapa.shortlink.project.dto.resp.*;
import com.github_Dididipapa.shortlink.project.service.LinkService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import java.util.Date;
import java.util.List;

/**
 * @description: To be defined
 * @author: dididi_papa
 * @email: mitis1624087624@gmail.com
 * @date: 2025/09/12  11:22
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/short-link/core/v1")
public class LinkController {
    private final LinkService linkService;

    /**
     * @description: 创建短链接
     * @author: dididi_papa
     * @date: 2025/9/12 上午11:45
     * @param: [linkCreateReqDTO]
     * @return: com.github_Dididipapa.shortlink.project.common.result.R<com.github_Dididipapa.shortlink.project.dto.resp.LinkCreateRespDTO>
     **/
    @PostMapping("/create")
    public R<LinkCreateRespDTO> createLink(@RequestBody LinkReqDTO linkReqDTO) {
        return Rs.success(linkService.createLink(linkReqDTO));
    }

    /**
     * @description: 分页查询短链接
     * @author: dididi_papa
     * @date: 2025/9/12 下午7:19
     * @param: [requestParam]
     * @return: com.github_Dididipapa.shortlink.project.common.result.R<com.baomidou.mybatisplus.core.metadata.IPage<com.github_Dididipapa.shortlink.project.dto.resp.PageRespDTO>>
     **/
    @GetMapping("/page")
    public R<IPage<PageRespDTO>> page(@RequestBody PageReqDTO requestParam) {
        return Rs.success(linkService.pageLink(requestParam));
    }

    /**
     * @description: 修改短链接
     * @author: dididi_papa
     * @date: 2025/9/12 下午7:32
     * @param: [linkReqDTO]
     * @return: com.github_Dididipapa.shortlink.project.common.result.R
     **/
    @PostMapping("/update")
    public R<Void> updateLink(@RequestBody LinkUpdateReqDTO linkReqDTO) {
        linkService.updateLink(linkReqDTO);
        return Rs.success();
    }

    /**
     * @description: 批量创建短链接
     * @author: dididi_papa
     * @date: 2025/9/14 下午2:00
     * @param: [linkBatchReqDTO]
     * @return: com.github_Dididipapa.shortlink.project.common.result.R
     **/
    @PostMapping("/create/batch")
    public R createLinkBatch(@RequestBody LinkBatchReqDTO linkBatchReqDTO) {
        linkService.createLinkBatch(linkBatchReqDTO);
        return Rs.success();
    }

    /**
     * @description: 获取标题
     * @author: dididi_papa
     * @date: 2025/9/14 下午6:22
     * @param: [url]
     * @return: com.github_Dididipapa.shortlink.project.common.result.R<java.lang.String>
     **/
    @GetMapping("title")
    public R<String> getTitle(@RequestParam String url) {
        return Rs.success(linkService.getTitle(url));
    }

    /**
     * @description: 回收站保存
     * @author: dididi_papa
     * @date: 2025/9/14 下午6:36
     * @param: [linkDeleteReqDTO]
     * @return: com.github_Dididipapa.shortlink.project.common.result.R
     **/
    @DeleteMapping("/recycle-bin/save")
    public R<Void> recycleBinSave(@RequestBody RecycleBinLinkReqDTO recycleBinLinkReqDTO) {
        linkService.recycleBinSave(recycleBinLinkReqDTO);
        return Rs.success();
    }

    /**
     * @description: 回收站分页查询
     * @author: dididi_papa
     * @date: 2025/9/14 下午7:21
     * @param: []
     * @return: com.github_Dididipapa.shortlink.project.common.result.R<com.baomidou.mybatisplus.core.metadata.IPage<com.github_Dididipapa.shortlink.project.dto.resp.RecyleBinRespDTO>>
     **/
    @GetMapping("/recycle-bin/page")
    public R<IPage<RecyleBinRespDTO>> recycleBinPage(@RequestBody RecycleBinPageReqDTO requestParam) {
        return Rs.success(linkService.pageRecycleBinLink(requestParam));
    }

    /**
     * @description: 恢复短链接
     * @author: dididi_papa
     * @date: 2025/9/14 下午7:35
     * @param: [recycleBinLinkReqDTO]
     * @return: com.github_Dididipapa.shortlink.project.common.result.R
     **/
    @PostMapping("/recycle-bin/recover")
    public R recoverLink(@RequestBody RecycleBinLinkReqDTO recycleBinLinkReqDTO) {
        linkService.recoverLink(recycleBinLinkReqDTO);
        return Rs.success();
    }

    /**
     * @description: 移除短链接
     * @author: dididi_papa
     * @date: 2025/9/15 下午6:58
     * @param: [recycleBinLinkReqDTO]
     * @return: com.github_Dididipapa.shortlink.project.common.result.R
     **/
    @PostMapping("/recycle-bin/remove")
    public R removeLink(@RequestBody RecycleBinLinkReqDTO recycleBinLinkReqDTO) {
        linkService.removeLink(recycleBinLinkReqDTO);
        return Rs.success();
    }

    /**
     * @description: 获取短链接分组统计
     * @author: dididi_papa
     * @date: 2025/9/16 下午4:01
     * @param: []
     * @return: com.github_Dididipapa.shortlink.project.common.result.R<java.util.List<com.github_Dididipapa.shortlink.project.dto.resp.LinkGroupCountRespDTO>>
     **/
    @GetMapping("/count")
    public R<List<LinkGroupCountRespDTO>> listGroupShortLinkCount(List<String> reqestParams) {
        return Rs.success(linkService.listGroupShortLinkCount(reqestParams));
    }
}
